package com.cl.mybatis.learn.day09;

import java.sql.Connection;
import java.util.Properties;

import javax.sql.DataSource;

import org.apache.ibatis.session.TransactionIsolationLevel;
import org.apache.ibatis.transaction.Transaction;
import org.apache.ibatis.transaction.TransactionFactory;
import org.apache.ibatis.transaction.jdbc.JdbcTransactionFactory;

/**
 * 定义自己的事务管理器,实现获取连接、提交、回滚、关闭数据库连接等操作
 */
public class MyTransactionFactory extends JdbcTransactionFactory implements TransactionFactory {
    public MyTransactionFactory() {
        super();
    }
    
    // set 属性注入
    @Override
    public void setProperties(Properties props) {
        System.out.println("获取属性：" + props);
    }
    
    @Override
    public Transaction newTransaction(Connection conn) {
        System.out.println("创建事务1：");
        return super.newTransaction(conn);
    }
    
    @Override
    public Transaction newTransaction(DataSource ds, TransactionIsolationLevel level, boolean autoCommit) {
        System.out.println("创建事务2：");
        return super.newTransaction(ds, level, autoCommit);
    }
}